//
//  JobLogViewController.m
//  云律司
//
//  Created by 韦淋 on 2017/6/19.
//  Copyright © 2017年 test. All rights reserved.
//

#import "JobLogViewController.h"

@interface JobLogViewController ()<UITableViewDelegate,UITableViewDataSource>


@property (nonatomic, strong) UITableView *jobLogTablewView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) UIButton *barAddButton;
@property (nonatomic, strong) NSDictionary *log_Type;
@end

@implementation JobLogViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.barTitleLable.text = @"日志列表 ";
    self.dataSource = [NSMutableArray array];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [self getDataSource];
    [self initUI];
    
}
- (void)getDataSource{
    [NetworkingManager getUrl:[NSString stringWithFormat:@"%@glid=%@",JOBLOGLIST_URL,self.caseDetailDic[@"id"]] dic:nil Succeed:^(id responseData) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        self.dataSource = responseData[@"result"];
        if (self.dataSource.count == 0) {
            [MBProgressHUD showSuccess:@"暂无更多数据"];
        }
        NSLog(@"LogList = %@",self.dataSource);
        [self.jobLogTablewView reloadData];
        [self.jobLogTablewView.mj_header endRefreshing];
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"网络异常"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}
- (void)initUI{
    
    [self.view addSubview:self.jobLogTablewView];
    
    [self.view addSubview:self.barAddButton];
}
- (void)loadNewData{
    [self.dataSource removeAllObjects];
    [self getDataSource];
}
#pragma mark - Button Target
- (void)action_AddButton:(UIButton *)sender{
    AddInfoViewController *addVC = [[AddInfoViewController alloc] init];
    addVC.flag = self.log;
    addVC.caseDetailDic = self.caseDetailDic;
    [self.navigationController pushViewController:addVC animated:YES];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    JobLogCell *cell = [tableView dequeueReusableCellWithIdentifier:@"jobLogCell" forIndexPath:indexPath];
    cell.titleLable.text = self.dataSource[indexPath.row][@"create_date"];
    
    NSString *key = self.dataSource[indexPath.row][@"log_type"];
    NSString *log_type = [self.log_Type valueForKey:key];
    cell.logType.text = [NSString stringWithFormat:@"日志类型： %@",log_type];
    
    cell.caseLable.text = [NSString stringWithFormat:@"案件： %@",self.dataSource[indexPath.row][@"ah_number"]];
    cell.jobDescription.text = [NSString stringWithFormat:@"工作描述： %@",self.dataSource[indexPath.row][@"bzsm"]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    CaseDetailViewController *CDVC = [[CaseDetailViewController alloc] init];
//    [self.navigationController pushViewController:CDVC animated:YES];
}
#pragma mark - Getter
- (NSDictionary *)log_Type{
    if (!_log_Type) {
        _log_Type = [NSDictionary dictionaryWithObjectsAndKeys:@"客户拜访",@"1",@"商务谈判",@"2",@"法律咨询",@"3",@"案例/资料检索",@"4",@"法律文书起草/修改",@"5",@"调查取证",@"6",@"案件研讨",@"7",@"刑案律师会见",@"8",@"诉讼/仲裁出庭",@"9",@"信访/社区/法援律师值班",@"10", nil];
    }
    return _log_Type;
}
- (UITableView *)jobLogTablewView{
    if (!_jobLogTablewView) {
        _jobLogTablewView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) style:UITableViewStyleGrouped];
        _jobLogTablewView.backgroundColor = [UIColor clearColor];
        _jobLogTablewView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _jobLogTablewView.delegate = self;
        _jobLogTablewView.dataSource = self;
        _jobLogTablewView.estimatedRowHeight = 180;
        [_jobLogTablewView registerClass:[JobLogCell class] forCellReuseIdentifier:@"jobLogCell"];
        _jobLogTablewView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
        
    }
    return _jobLogTablewView;
}
- (UIButton *)barAddButton{
    if (!_barAddButton) {
        _barAddButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _barAddButton.hidden = self.hideOrNot;
        _barAddButton.frame = CGRectMake(335, 30, 25, 25);
        [_barAddButton setBackgroundImage:[UIImage imageNamed:@"jiahao"] forState:UIControlStateNormal];
        [_barAddButton addTarget:self action:@selector(action_AddButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _barAddButton;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
